﻿# -*- coding:utf-8 -*- #
from probe.core.level import *
from commands import *
def slave_status(args):
    '''监控mysql主从状态(热备服务器专用)'''
    username = 'ywjk'
    password = 'OAXBF1bmswTOftFRBsHh'
    result = getstatusoutput(('''/opt/mysql5.0/bin/mysql -u%s -p%s -e "show slave status \G;"|grep Slave|grep -v Slave_IO_State|awk '{print $2}' ''')%(username,password))
    if result[0]!=0:
        return WarningData({'连接Mysql错误': [int(result[0]), '']})
    for i in result[1].split('\n'):
        if i != 'Yes':
            return WarningData({'主从服务器备份检测': [-1, 'Error']})
    return InfoData({'主从服务器备份检测': [int(len(result[1])), 'Yes']})
if __name__ == '__main__':
    print slave_status()
